use ".\data\clean\revision1\lag_ivs_plaza1_incomplete",clear
append using ".\data\clean\revision1\lag_ivs - Copy"
* first var # is plaza and second is lag #*5 min
forval t=1/3{
	forval p=1/5{
		replace mean_t_`p'_`t'=. if plaza<`p'
		replace mean_d_`p'_`t'=. if plaza<`p'
	}
}
tempfile iv
save `iv'

local fn .\data\clean\I10W_laneuse_dataset_15nov14_wcensus
use "`fn'", clear
drop if holiday==1 | dow==0 | dow==6
keep if inlist(hour, 5,6,7,8)
gen EL_TT=dist/ELspeed
gen ML_TT=dist/MLspeed
gen TT_dif_hr=ML_TT-EL_TT
drop if TT_dif_hr==.
g double time_five = 5 * 60000 * floor(entry_time / (5 * 60 * 1000))
format %tc time_five
sort time_five
egen t=group(time_five)
qui sum t
local maxt=`r(max)'
g p=substr(entry_plaza,-1,.)
destring p, replace
ren p plaza
ren time time_old
ren t time
merge m:1 plaza time using `iv'
keep if _m==3
keep date hour min rt_id mean_*
drop mean_inc
duplicates drop date hour min rt_id, force
save ".\data\clean\revision1\prelim_IVs", replace
